Page({
  data: {
    isDarkMode: false
  },
  onLoad() {
    const app = getApp();
    const isDark = wx.getStorageSync('isDarkMode');
    this.setData({
      isDarkMode: typeof isDark === 'boolean' ? isDark : (app.globalData.isDarkMode || false)
    });
  },
  toggleDarkMode(e) {
    const isDark = e.detail.value;
    this.setData({ isDarkMode: isDark });
    getApp().globalData.isDarkMode = isDark;
    wx.setStorageSync('isDarkMode', isDark);
    wx.showToast({
      title: isDark ? '已开启夜间模式' : '已关闭夜间模式',
      icon: 'none'
    });
    // 通知所有页面刷新主题
    const pages = getCurrentPages();
    pages.forEach(page => {
      if (page.updateTheme) page.updateTheme(isDark);
    });
  },
  navigateToAccount() {
    wx.navigateTo({
      url: '/pages/account/account'
    });
  },
  navigateToPrivacy() {
    wx.navigateTo({
      url: '/pages/privacy/privacy'
    });
  },
  navigateToFeedback() {
    wx.navigateTo({
      url: '/pages/feedback/feedback'
    });
  },
  navigateToAbout() {
    wx.navigateTo({
      url: '/pages/about/about'
    });
  },
  logout() {
    wx.showModal({
      title: '退出登录',
      content: '确定要退出登录吗？',
      success: (res) => {
        if (res.confirm) {
          wx.clearStorageSync();
          wx.reLaunch({ url: '/pages/index/index' });
        }
      }
    });
  }
}); 